var cityData = require('../../../utils/city.js');
var  base64  =  require('../../../utils/base64.js');

Page({
  data: {
    iconSize: [20, 30, 40, 50, 60, 70],
    iconColor: [
      'red', 'orange', 'yellow', 'green', 'rgb(0,255,255)', 'blue', 'purple'
    ],
    iconType: [
      'success', 'success_no_circle', 'info', 'warn', 'waiting', 'cancel', 'download', 'search', 'clear'
    ],
    content: [],

    nv: [],

    px: [],

    qyopen: false,

    qyshow: false,

    nzopen: false,

    pxopen: false,

    nzshow: false,

    pxshow: false,

    isfull: false,

    cityleft: cityData.getCity(),

    citycenter: {},

    cityright: {},

    select1: '',

    select2: '',

    shownavindex: '',
    fylist: {}
  },
  onLoad: function () {

    this.setData({

      nv: ['衣服', '裤子', '内衣', '服饰', '衣服', '裤子', '内衣', '服饰', '衣服', '裤子', '内衣', '服饰'],

      px: ['默认排序', '离我最近', '价格最低', '价格最高']

    });
    this.RequestData();

  },

  listqy: function (e) {

    if (this.data.qyopen) {

      this.setData({

        qyopen: false,

        nzopen: false,

        pxopen: false,

        nzshow: true,

        pxshow: true,

        qyshow: false,

        isfull: false,

        shownavindex: 0

      })

    } else {

      this.setData({

        qyopen: true,

        pxopen: false,

        nzopen: false,

        nzshow: true,

        pxshow: true,

        qyshow: false,

        isfull: true,

        shownavindex: e.currentTarget.dataset.nav

      })

    }



  },

  list: function (e) {

    if (this.data.nzopen) {

      this.setData({

        nzopen: false,

        pxopen: false,

        qyopen: false,

        nzshow: false,

        pxshow: true,

        qyshow: true,

        isfull: false,

        shownavindex: 0

      })

    } else {

      this.setData({

        content: this.data.nv,

        nzopen: true,

        pxopen: false,

        qyopen: false,

        nzshow: false,

        pxshow: true,

        qyshow: true,

        isfull: true,

        shownavindex: e.currentTarget.dataset.nav

      })

    }

  },

  listpx: function (e) {

    if (this.data.pxopen) {

      this.setData({

        nzopen: false,

        pxopen: false,

        qyopen: false,

        nzshow: true,

        pxshow: false,

        qyshow: true,

        isfull: false,

        shownavindex: 0

      })

    } else {

      this.setData({

        content: this.data.px,

        nzopen: false,

        pxopen: true,

        qyopen: false,

        nzshow: true,

        pxshow: false,

        qyshow: true,

        isfull: true,

        shownavindex: e.currentTarget.dataset.nav

      })

    }

    console.log(e.target)

  },

  selectleft: function (e) {



    this.setData({

      cityright: {},

      citycenter: this.data.cityleft[e.currentTarget.dataset.city],

      select1: e.target.dataset.city,

      select2: ''

    });

  },

  selectcenter: function (e) {



    this.setData({

      cityright: this.data.citycenter[e.currentTarget.dataset.city],

      select2: e.target.dataset.city

    });

  },

  selectright: function (e) {
    this.setData({
      select3: e.target.dataset.city
    });
    wx.showToast({
      title: e.target.dataset.city,
      icon: 'success',
      duration: 2000
    });
  },

  hidebg: function (e) {
    this.setData({

      qyopen: false,

      nzopen: false,

      pxopen: false,

      nzshow: true,

      pxshow: true,

      qyshow: true,

      isfull: false,

      shownavindex: 0

    })
  },
  //加载房源数据
  RequestData: function () {
    var that = this;
    wx.request({
      url: 'https://zf.8glist.com/api/House/GetList/0/1/100',
      header: {
        'authorization': "Basic " + base64.encode('admin:120C39D1-9FFF-4974-8D6D-E8E75F343475')
      },
      success: function (res) {
        that.setData({
          fylist: res.data.list
        })
      },
      fail: function (err) {
        wx.showToast({
          title: err.errMsg,
          icon: 'success',
          duration: 2000
        })
      }
    });
  },
  //点击标题进入房源详情
  showHouseDetail: function (e) {
    wx.navigateTo({
      url: '/pages/ZuFang/zf_detail/zf_detail',
      success: function (res) {
        // success
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
      }
    });
  }

});